package sfeir.authform.server.authservice;

import sfeir.authform.client.dao.AuthUser;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class AuthServiceGoogle implements AuthService {
    private UserService service = UserServiceFactory.getUserService();
    
    @Override
    public int getAuthType() {
        return AuthServiceFactory.GOOGLE;
    }

    @Override
    public AuthUser getCurrentUser() {
        com.google.appengine.api.users.User gUser = service.getCurrentUser();
        if (gUser != null) {
            AuthUser user = new AuthUser();
            user.setEmail(gUser.getEmail());
            user.setNickname(gUser.getNickname());
            user.setAuthDomain(gUser.getAuthDomain());
            return user;
        }
        return null;
    }

    @Override
    public Boolean isUserAdmin() {
        return service.isUserAdmin();
    }

    @Override
    public Boolean isUserLoggedIn() {
        return service.isUserLoggedIn();
    }

    @Override
    public String createLoginURL(String destinationURL) {
        return service.createLoginURL(destinationURL);
    }

    @Override
    public String createLogoutURL(String destinationURL) {
        return service.createLogoutURL(destinationURL);
    }

}
